package com.gjy.nacos.server.controller;

import com.gjy.nacos.server.domain.User;
import com.gjy.nacos.server.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-03-08 11:11:36
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/saveThr")
    public User saveUser(@RequestBody User user) {
        return userService.saveUser(user);
    }

    @PostMapping("/save/{type}")
    public Integer createUser(@PathVariable("type") Boolean type, @RequestBody User user) {
        return userService.saveUser(user, type);
    }

    @PostMapping("/find")
    public List<User> getAllUsers(@RequestBody User user) {
        return userService.findUsersGtAge(user.getAge());
    }

    @PostMapping("/delete")
    public Integer deleteUser(@RequestBody User user) {
        return userService.deleteUserById(user.getId());
    }

    @PostMapping("/update")
    public Integer updateUser(@RequestBody User user) {
        return userService.updateUserEmailById(user.getEmail(), user.getId());
    }

}
